package com.kkks.spring_rest.tick.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.kkks.spring_rest.tick.model.WhoUserBaseInfo;
import com.kkks.spring_rest.tick.model.pojo.WhoUserLogin;
import com.kkks.spring_rest.tick.service.UserService;
import com.kkks.spring_rest.tick.utils.ConstantUtils;

@Controller
@RequestMapping("/welcome")
// 将Model中属性名为Constants.USER_INFO_SESSION的属性放到Session属性列表中，以便这个属性可以跨请求访问
@SessionAttributes(com.kkks.spring_rest.tick.utils.ConstantUtils.USER_INFO_SESSION)
public class WelcomeController {

	@Autowired
	private UserService userService;

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	@RequestMapping(method = RequestMethod.POST)
	public String helloWorld(WhoUserBaseInfo whoUserBaseInfo, Model model) {
		WhoUserLogin whoUserLogin = this.userService.UserLogin(
				whoUserBaseInfo.getUserName(), whoUserBaseInfo.getPassword());

		model.addAttribute(ConstantUtils.USER_INFO_SESSION, whoUserLogin);
		return "welcome";
	}
}
